package com.pronosticnews.client.admin.view.main;

import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.pronosticnews.client.admin.ClientFactory;
import com.pronosticnews.client.admin.place.ChampionnatPlace;
import com.pronosticnews.client.admin.place.ClubPlace;
import com.pronosticnews.client.admin.place.JoueurPlace;
import com.pronosticnews.client.admin.place.MessagePlace;
import com.pronosticnews.client.admin.place.PaysPlace;
import com.pronosticnews.client.admin.place.SportPlace;
import com.pronosticnews.client.admin.place.StadePlace;
import com.pronosticnews.client.admin.resources.PronosticnewsAdminResources;

public class Menu extends Composite {

	interface MenuUiBinder extends UiBinder<Widget, Menu> {
	}

	private static MenuUiBinder binder = GWT.create(MenuUiBinder.class);

	@UiField
	Anchor pays;

	@UiField
	Anchor sport;

	@UiField
	Anchor championnat;

	@UiField
	Anchor club;

	@UiField
	Anchor joueur;

	@UiField
	Anchor stade;

	@UiField
	Anchor message;

	@UiField(provided=true)
	PronosticnewsAdminResources res;
	
	private ClientFactory clientFactory;

	public Menu(ClientFactory clientFactory) {
		this.clientFactory = clientFactory;
		res = GWT.create(PronosticnewsAdminResources.class);
		res.cssMenu().ensureInjected();
		initWidget(binder.createAndBindUi(this));
	}

	@UiHandler({ "pays", "sport", "championnat", "club", "joueur", "stade", "message" })
	public void doClick(ClickEvent event) {
		if (pays.equals(event.getSource())) {
			clientFactory.getPlaceController().goTo(new PaysPlace());
		}
		if (sport.equals(event.getSource())) {
			clientFactory.getPlaceController().goTo(new SportPlace());
		}
		if (championnat.equals(event.getSource())) {
			clientFactory.getPlaceController().goTo(new ChampionnatPlace());
		}
		if (club.equals(event.getSource())) {
			clientFactory.getPlaceController().goTo(new ClubPlace());
		}
		if (joueur.equals(event.getSource())) {
			clientFactory.getPlaceController().goTo(new JoueurPlace());
		}
		if (stade.equals(event.getSource())) {
			clientFactory.getPlaceController().goTo(new StadePlace());
		}
		if (message.equals(event.getSource())) {
			clientFactory.getPlaceController().goTo(new MessagePlace());
		}
	}
}
